package com.eric.domain.po;

import com.mybatisflex.annotation.*;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Table("tb_menu")
@Data
public class Menu implements Serializable {

    @Id(keyType = KeyType.Auto)
    private Long id;
    private Long parentId;
    private String name;
    private Integer version;

    @Column(isLogicDelete = true,onInsertValue = "0")
    private Integer isDeleted;

    @Column(value = "create_time", onInsertValue = "now()")
    private Date createTime;

    @Column(value = "update_time",onInsertValue = "now()", onUpdateValue = "now()")
    private Date updateTime;
    /*
    * 父子关系查询，如菜单
    * 递归算法
    * 第一个ManyToOne，parentId指向自己的parentId，targetField指向本身Menu类型的id
    * 多个子菜单的id指向一个父菜单的id（parentId）
    * */
    @RelationManyToOne(selfField = "parentId",targetField = "id")
    private Menu parent;
    /*
    * 递归算法
    * 一个父菜单的id（parentId）,对应多个子菜单的id    *
    * */
    @RelationOneToMany(selfField = "id",targetField = "parentId")
    private List<Menu> children;

}
